Ext.define('AmpleHarvest.objects.forms.irtCommon.requestInformation.requestCommon.requestDetails',
{
	extend			: 'Ext.form.Panel',
	alias			: 'widget.ampleharvest-objects-forms-irtcommon-requestinformation-requestcommon-requestdetails',
	requires		:
	[
		"Ext.form.field.Text", 
		"Ext.form.FieldSet",
		"Ext.form.field.Date", 
		'Ext.layout.container.VBox',
		'Ext.layout.container.HBox',
	],
		
	statics			: {},
	
	hideRequestUrgencyExplanation : function() {
		this.requestUrgencyInformation.hide();
		this.requestUrgencyInformation.getComponent("explanation_items").getComponent("explanation_textarea").disable();
	},
	
	showRequestUrgencyExplanation : function() {
		this.requestUrgencyInformation.getComponent("explanation_items").getComponent("explanation_textarea").enable();	
		this.requestUrgencyInformation.show();
	},
	
	initComponent	: function() {

		this.requestDetailsVBox = Ext.create("Ext.form.Panel", {
			collapsible	: false,
			border		: false,
			labelWidth	: 70,
			width		: 600,
			layout		: {
				type	: 'vbox',
		        align	: 'center'
			}
		});		

		//-------------------- Request Urgency --------------------//
		this.requestUrgency = Ext.create("Ext.form.FieldSet", {
			title		: "Urgency of Request",
			collapsible	: false,
			labelWidth	: 70,
			width		: 570,
			layout		: {
				type	: 'vbox',
		        align	: 'left'
			}
		});
		
		this.requestUrgencyFieldContainer = Ext.create('Ext.form.Panel', {
			border		: false,
			labelWidth	: 70,
			width		: 250,
			items: [{
	            xtype : 'checkboxgroup',
	            allowBlank : false,
			    defaultType	: 'radiofield',
			    defaults : { flex : 1 },
			    layout : { type : 'hbox' },
			    items : [
		            {
			            boxLabel	: 'Routine',
			            name: 'urgency', //PHP Column label
			            inputValue	: 'routine',
		                handler: function(checkbox, checked) {
		            		if(checked){
		            			this.up('ampleharvest-objects-forms-irtcommon-requestinformation-requestcommon-requestdetails').hideRequestUrgencyExplanation();
		            		}
		            	}
			        },
			        {
			            boxLabel	: 'Time Sensitive',
			            name: 'urgency', //PHP Column label
			            inputValue	: 'timesensitive',
		                handler: function(checkbox, checked) {
		            		if(checked){
		            			this.up('ampleharvest-objects-forms-irtcommon-requestinformation-requestcommon-requestdetails').showRequestUrgencyExplanation();
		            		}
		            	}
			        },
			    ]
			}]
		});
		
		
		
		this.requestUrgencyInformation = Ext.create("Ext.form.FieldSet", {
			border		: false,
			collapsible	: false,
			labelWidth	: 70,
			itemId		: 'explanation_fieldset',
			hidden		: true,
			items: [{
				border		: false,
				itemId			: 'explanation_items',
			    layout			: { type : 'vbox' },
			    align			: 'center',
			    items: 
			    [
			        {
			            xtype: 'text',
				        text: "Explanation:"
			        },
			        {
			        	xtype     : 'textarea',
			        	itemId	  : 'explanation_textarea',
						grow      : true,
			            name: 'urgency_explanation', //PHP Column label
						anchor    : '100%',
						width		: 530,
						allowBlank	: false
			        },
			    ]
			}]
		});
		
		this.requestDescriptionFieldSet = Ext.create("Ext.form.FieldSet",
		{
			title		: "Description",
			collapsible	: false,
			labelWidth	: 70,
			itemId		: 'description_fieldset',
			items: [
			{
				border		: false,
				itemId			: 'description_items',
			    layout			: { type : 'vbox' },
			    align			: 'center',
			    items: 
			    [
			        {
			        	xtype     : 'textarea',
			        	itemId	  : 'description_textarea',
						grow      : true,
			            name: 'description', //PHP Column label
						anchor    : '100%',
						width		: 550,
						allowBlank	: false
			        },
			    ]
			}]
		});
		
		this.requestJustificationFieldSet = Ext.create("Ext.form.FieldSet",
		{
			title		: "Justification",
			collapsible	: false,
			labelWidth	: 70,
			itemId		: 'justification_fieldset',
			items: [
			{
				border		: false,
				itemId			: 'justification_items',
			    layout			: { type : 'vbox' },
			    align			: 'center',
			    items: 
			    [
			        {
			        	xtype		: 'textarea',
			        	itemId		: 'justification_textarea',
						grow		: true,
			            name		: 'justification', //PHP Column label
						anchor		: '100%',
						width		: 550,
						allowBlank	: false
			        },
			    ]
			}]
		});
		
		this.requestUrgency.add( this.requestUrgencyFieldContainer );
		this.requestUrgency.add(this.requestUrgencyInformation);
		
		this.requestDetailsVBox.add(this.requestUrgency);
		this.requestDetailsVBox.add(this.requestDescriptionFieldSet);
		this.requestDetailsVBox.add(this.requestJustificationFieldSet);
		
		this.items = [ this.requestDetailsVBox ]
		
	    this.callParent();
	}
});